﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Configuration;

using Wind.Speed;
using Wind.MultimediaStation.WebService.Entity;

using Wind.Utils;

namespace Wind.MultimediaStation.WebService
{
    /// <summary>
    /// SpeedSharp
    /// </summary>
    public class MultimediaStationSpeedSharpBusiness
    {
        private string SpeedServerIP="114.80.154.39";
        private int SpeedServerPort=433;
        private int MaxConnections=10;
        public MultimediaStationSpeedSharpBusiness()
        {
            SpeedServerIP = ConfigurationSettings.AppSettings["SpeedServerIP"] == "" ? "114.80.154.39" : ConfigurationSettings.AppSettings["SpeedServerIP"];
            SpeedServerPort = ConfigurationSettings.AppSettings["SpeedServerPort"] == "" ? 433 : int.Parse(ConfigurationSettings.AppSettings["SpeedServerPort"]);
            MaxConnections = ConfigurationSettings.AppSettings["MaxConnections"] == "" ? 10 : int.Parse(ConfigurationSettings.AppSettings["MaxConnections"]);
        }
        /// <summary>
        /// 排行榜数据
        /// </summary>
        /// <param name="SystemSectorName">指数名称</param>
        /// <param name="TopN">前几条</param>
        /// <param name="BottomN">后几条</param>
        /// <returns>排行榜数据</returns>
        public SpeedSharpChartData GetSpeedSharpChartData(string SystemSectorName, uint TopN, uint BottomN)
        {
            SpeedSharpContext ssc = SpeedSharpContext.InitContext(SpeedServerIP, SpeedServerPort, MaxConnections);
            return ssc.GetSpeedSharpChartData(SystemSectorName, TopN, BottomN);
        }
        /// <summary>
        /// 分时图行情数据
        /// </summary>
        /// <param name="WindCode">WindCode</param>
        /// <param name="StartTime">开始时间100000 10点钟 全天是0</param>
        /// <returns></returns>
        public TrendIntraDayData GetTrendIntraDayData(string WindCode, uint StartTime)
        {
            SpeedSharpContext ssc = SpeedSharpContext.InitContext(SpeedServerIP, SpeedServerPort, MaxConnections);
            return ssc.GetTrendIntraDayData(WindCode, StartTime);
        }
        /// <summary>
        /// 获取实时行情
        /// </summary>
        /// <param name="WindCode">WindCode</param>
        /// <returns>获取实时行情</returns>
        public DataLines GetSectorMDSnapshot(string WindCode)
        {
            //string[] inds = new string[]{"交易日期","交易时间","最新价","前收价","开盘价","最高价","最低价","涨跌","涨跌幅","成交额","上涨家数","下跌家数","停盘家数"};
            UInt32[] inds = new UInt32[] {1, 2, 3, 4, 5, 6, 7, 80, 81, 59, 217, 218, 219 };
            String[] UserSector = new String[] { WindCode };
            SpeedSharpContext ssc = SpeedSharpContext.InitContext(SpeedServerIP, SpeedServerPort, MaxConnections);
            return ssc.GetSectorMDSnapshot(UserSector, inds, SpeedSharpDef.BondPricingType_DirtyPrice, 81, SpeedSharpDef.SortDirection_Desc);
        }
    }

}
